//
//  FriendCustomAlertView.m
//  AGG_V2
//
//  Created by MacMini on 16/2/1.
//  Copyright © 2016年 admin. All rights reserved.
//

#import "FriendCustomAlertView.h"
@interface FriendCustomAlertView()

@property (nonatomic, copy) NSString *contentStr;

@property (nonatomic, strong) UIView *contentView;

@property (nonatomic, strong) UITextField *inputField;
@end

@implementation FriendCustomAlertView

- (instancetype)init{
    self = [super init];
    
    if (self) {
        self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        self.backgroundColor = [UIColor clearColor];
        
        UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        coverView.backgroundColor = [UIColor darkTextColor];
        coverView.alpha = 0.3;
        [self addSubview:coverView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
        [coverView addGestureRecognizer:tap];
        
    }
    return self;
}

- (instancetype)initFriendCustomAlertView;{
    self = [self init];
    _contentView = [[UIView alloc] initWithFrame:CGRectMake((WIDTH - 300)/2, (HEIGHT - 140)/2, 300, 140)];
    _contentView.backgroundColor = [UIColor whiteColor];
    _contentView.layer.masksToBounds = YES;
    _contentView.layer.cornerRadius = 8.0f;
    [self addSubview:_contentView];
    
    UILabel *titleLabel      = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 48)];
    titleLabel.text          = @"发送验证申请";
    titleLabel.textColor     = [UIColor redColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font          = [UIFont systemFontOfSize:16];
    [_contentView addSubview:titleLabel];
    
    UIView *fieldView             = [[UIView alloc] initWithFrame:CGRectMake(35, 48, 230, 32)];
    fieldView.backgroundColor     = [UIColor redColor];
    fieldView.layer.masksToBounds = YES;
    fieldView.layer.cornerRadius  = 16.0f;
    fieldView.layer.borderWidth   = 1;
    fieldView.layer.borderColor   = [UIColor redColor].CGColor;
    [_contentView addSubview:fieldView];
    
    _inputField           = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, 214, 32)];
    _inputField.textColor = [UIColor greenColor];
    _inputField.font      = [UIFont systemFontOfSize:16];
    _inputField.text      = [NSString stringWithFormat:@"我是热风"];
    _contentStr           = [NSString stringWithFormat:@"我是叶日晚"];
    [fieldView addSubview:_inputField];
    
    UIView *lineView         = [[UIView alloc] initWithFrame:CGRectMake(0, 96, 300, 0.5)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [_contentView addSubview:lineView];
    
    UIView *lineView2         = [[UIView alloc] initWithFrame:CGRectMake(150, 96, 0.5, 45)];
    lineView2.backgroundColor = [UIColor lightGrayColor];
    [_contentView addSubview:lineView2];
    
    UIButton *cancelButton       = [[UIButton alloc] initWithFrame:CGRectMake(0, 96, 150, 44)];
    cancelButton.backgroundColor = [UIColor clearColor];
    [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    cancelButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
    [cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
    [_contentView addSubview:cancelButton];
    
    UIButton *sureButton       = [[UIButton alloc] initWithFrame:CGRectMake(150, 96, 150, 44)];
    sureButton.backgroundColor = [UIColor clearColor];
    [sureButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
    [sureButton addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
    [_contentView addSubview:sureButton];
    
    return  self;
}

- (void)handleTap:(UITapGestureRecognizer *)aTap {
    [self removeFromSuperview];
}

- (void)cancelAction:(UIButton *)btn{
    [self removeFromSuperview];
}

- (void)sureAction:(UIButton *)btn{
    if (self.delegate) {
        NSString *tempContent;//如果未使用删除
        if (_inputField.text.length == 0) {
            tempContent = _contentStr;
        } else {
            tempContent = _inputField.text;
        }
        [self.delegate addFriendApplyCntent:_inputField.text withFriendName:_friendName];
    }
}

@end
